import django_filters
from main.filters import NumberInFilter
from main.models import AttachmentGroups
from main.permissions import DjangoModelFullPermissions
from rest_framework import serializers, viewsets


class AttachmentGroupsSerializer(serializers.ModelSerializer):
    class Meta:
        model = AttachmentGroups
        fields = (
            "id",
            "name",
            "description",
            "created_on",
            "updated_on",
        )


class AttachmentGroupsFilter(django_filters.FilterSet):
    ids = NumberInFilter(field_name="id", lookup_expr="in")

    class Meta:
        model = AttachmentGroups
        fields = ("id", "name")


class AttachmentGroupsViewSet(viewsets.ModelViewSet):
    queryset = AttachmentGroups.objects.all()
    serializer_class = AttachmentGroupsSerializer
    permission_classes = (DjangoModelFullPermissions,)
    filter_backends = [
        django_filters.rest_framework.DjangoFilterBackend,
    ]
    filterset_class = AttachmentGroupsFilter
